package ciyuan.Item.TypeInterface.WeaponType;

import net.minecraft.block.BlockState;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.BowItem;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public abstract class BowType extends BowItem implements WeaponType{

    public BowType(Properties p_i48522_1_) {
        super(p_i48522_1_);
    }

    @Override
    public void onUseTick(World p_219972_1_, LivingEntity livingEntity, ItemStack itemStack, int p_219972_4_) {
        super.onUseTick(p_219972_1_, livingEntity, itemStack, p_219972_4_);
        float a = livingEntity.getUseItem() != itemStack ? 0.0F : (float)(itemStack.getUseDuration() - livingEntity.getUseItemRemainingTicks()) / 20.0F;
        if (a>=1) {
            livingEntity.releaseUsingItem();
        }
        if (!livingEntity.hasEffect(Effects.MOVEMENT_SPEED)) {
            livingEntity.addEffect(new EffectInstance(Effects.MOVEMENT_SPEED,1,10));
        }
    }

    @Override
    public void releaseUsing(ItemStack p_77615_1_, World p_77615_2_, LivingEntity livingEntity, int p_77615_4_) {
        super.releaseUsing(p_77615_1_, p_77615_2_, livingEntity, p_77615_4_);
    }

    @Override
    public boolean canAttackBlock(BlockState p_195938_1_, World p_195938_2_, BlockPos p_195938_3_, PlayerEntity p_195938_4_) {
        return false;
    }

    @Override
    public boolean canBeDepleted() {
        return false;
    }

    @Override
    public int getUseDuration(ItemStack p_77626_1_) {
        return super.getUseDuration(p_77626_1_);
    }

    @Override
    public boolean hurtEnemy(ItemStack p_77644_1_, LivingEntity p_77644_2_, LivingEntity p_77644_3_) {
        p_77644_1_.hurtAndBreak(1, p_77644_3_, (p_220045_0_) -> {
            p_220045_0_.broadcastBreakEvent(EquipmentSlotType.MAINHAND);
        });
        return true;
    }

}